angular.module('starter.controllers')
.controller('CenterCtrl', function($scope, museumFac, $stateParams, $location, $cookies) {
    $scope.change_language = function(id){
      $scope.language = id;
      var expireDate = new Date();  
      expireDate.setDate(expireDate.getDate() + 30);                
      $cookies.put('language', id, {'expires': expireDate.toUTCString()});
      location.reload();
      if(id == 0){
        document.getElementById('title').innerHTML = '提示';
        document.getElementById('windowclosebutton').value = '确定';
      }else{
        document.getElementById('title').innerHTML = 'Hint';
        document.getElementById('windowclosebutton').value = 'Confirm';
      }

    }

  $scope.getLanguage = function(){
    $scope.language = $cookies.get('language');
    if($scope.language){
        $scope.language = $scope.language;
    }else{
        $scope.language = 0;
    }
    if($scope.language == 0){
      document.getElementById('title').innerHTML = '提示';
      document.getElementById('windowclosebutton').value = '确定';
    }else{
      document.getElementById('title').innerHTML = 'Hint';
      document.getElementById('windowclosebutton').value = 'Confirm';
    }
  }
  $scope.getLanguage();
  
  $scope.gotoTicket = function(){
  	$location.url('my_ticket');
  }

  $scope.gotoInfo = function(){
  	$location.url('info');
  }

  $scope.gotoQrcode = function(){
  	$location.url('qrcode');
  }

  $scope.backhome = function(){
	  $location.url('home');
  }

  $scope.gotoOrder = function(){
    $location.url('order');
  }

  $scope.checkOpenid = function(){
	museumFac.user.usertest(function(data){
        $scope.is_login = data.info;
      },function(data){
        alert(data.data.info);
    });
  }
  $scope.checkOpenid();

  $scope.gotoCenter = function(){
  	if($scope.is_login == true){
  		$location.url('center');
  	}else{
      $scope.url = window.location.href;
      $cookies.put('lastPage', $scope.url);
  		$location.url('login');
  	}	
  }

  $scope.getUser = function() {
    museumFac.user.profile(function(data){
      $scope.user = data.info;
    },function(data){
      alert(data.data.info);
    });
  };
  $scope.getUser();

  $scope.gotoVip = function(){
    window.location.href = 'http://store.sifangartmuseum.org.cn/Home/Index/vip';
  }
})